#include <bits/stdc++.h>
#include "../../tools/tools.h"
using namespace std;

constexpr int INF = 0x7fffffff; // 无穷大
typedef long long ll;

class Solution {
public:
    int maximumLength(vector<int>& nums, int k) {
        const int n = nums.size();
        vector dp(n + 1, vector<int>(k, 0));
        int ans = 0;
        for (int i = 1; i < n; i++) {
            vector<bool> visit(k, false);
            int vist_cnt = 0;
            for (int j = i - 1; j >= 0 && vist_cnt < k; j--) {
                int y = (nums[i] + nums[j]) % k;
                if (!visit[y]) {
                    vist_cnt++;
                    visit[y] = true;
                    dp[i][y] = dp[j][y] + 1;
                    ans = max(ans, dp[i][y]);
                }
            }
        }
        return ans + 1;
    }
};

int main(int argc, const char** argv) {
    Solution s;
    vector<int> d;
    debug(s.maximumLength(d = {1,2,3,4,5}, 2));
    debug(s.maximumLength(d = {1,4,2,3,1,4}, 3));

    return 0;
}
